import { defineStore } from 'pinia';
import { useStorage } from '@vueuse/core'; // 使用 vueuse 的 useStorage 来持久化状态

// 定义 Pinia Store
export const useResourceStore = defineStore('resource', () => {
  // 使用 useStorage 将数据持久化到 localStorage
  const resourceid = useStorage<string | null>('resourceid', null); // 第一个参数是 key，第二个参数是初始值
  const type = useStorage<string | null>('type', null);
  const sortid = useStorage<number | null>('sortid', null);

  // Actions
  const setResourceid = (newResourceid: string) => {
    resourceid.value = newResourceid;
  };

  const setType = (newType: string) => {
    type.value = newType;
  };

  const setSortid = (newSortid: number) => {
    sortid.value = newSortid;
  };
  return {
    resourceid,
    type,
    sortid,
    setResourceid,
    setType,
    setSortid,
  };
});
